package weaver.interfaces.cese.duss.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import weaver.general.Util;
import weaver.interfaces.cese.duss.ceseutil.WorkflowCreateHandler;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-02-23
 * @Description: 创建待办流程
 * @ModifyLog:
 **/
@WebServlet("/workflow/createWorkflow")
public class CreateWorkflowServiceImpl extends HttpServlet {
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        super.doPost( req, res );
    }

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String creatorId = Util.null2String( req.getParameter("creatorId"));//创建人
        String workflowId = Util.null2String( req.getParameter("workflowId"));//流程ID
        String requestName = Util.null2String( req.getParameter("requestName"));//流程名称
        String IsNextFlow = Util.null2String( req.getParameter("IsNextFlow"));//是否提交下一节点
        String mainTable= Util.null2String( req.getParameter("mainTable"));//主表字段
        PrintWriter out = res.getWriter();
        WorkflowCreateHandler handler = new WorkflowCreateHandler();
        try {
            HashMap<String, String> requestMainMap = JSON.parseObject(mainTable, HashMap.class);
            String requestid = handler.WorkflowCreateByRequestMap( creatorId, workflowId, requestName, IsNextFlow, requestMainMap );
            JSONObject resultJson = new JSONObject(  );
            resultJson.put("requestid",requestid);
            out.print(resultJson.toJSONString());
        } catch (Exception e) {
            e.printStackTrace();
            out.print("request error");
        }
    }
}
